#include "qtedelegate.h"

QteDelegate::QteDelegate(QObject *parent) :
    QItemDelegate(parent)
{
}

void QteDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{

    int qte = index.data(Qt::DisplayRole).toInt();
    QString texte = "x " + QString::number(qte);
    if(qte == 0){
       texte = "";
    }
    QStyleOptionViewItem myoption = option;
    myoption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
    QPalette *mapalette = new QPalette();
    mapalette->setColor(QPalette::Text,QColor(255,125,0));
    myoption.palette = *mapalette;

    drawDisplay(painter, myoption, myoption.rect , texte);
    //drawFocus(painter, myoption, myoption.rect);

}

QSize QteDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QSize size = option.fontMetrics.boundingRect("x "+QString::number(index.data().toInt())).size();
    size.setWidth(size.width()+15);
    return size;

}
